package com.sugar.real.estate.module.business.dal.mysql.buildhouse;

import cn.hutool.core.util.StrUtil;
import com.sugar.real.estate.framework.common.pojo.PageResult;
import com.sugar.real.estate.framework.mybatis.core.mapper.BaseMapperX;
import com.sugar.real.estate.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.sugar.real.estate.module.business.controller.admin.buildhouse.vo.BuildHousePageReqVO;
import com.sugar.real.estate.module.business.dal.dataobject.buildhouse.BuildHouseDO;
import org.apache.ibatis.annotations.Mapper;

/**
 * 建房 Mapper
 *
 * @author Ysugar
 */
@Mapper
public interface BuildHouseMapper extends BaseMapperX<BuildHouseDO> {

    default PageResult<BuildHouseDO> selectPage(BuildHousePageReqVO reqVO) {
        String location = reqVO.getLocationZhCn();
        return selectPage(reqVO, new LambdaQueryWrapperX<BuildHouseDO>()
                .betweenIfPresent(BuildHouseDO::getCreateTime, reqVO.getCreateTime())
                .nested(StrUtil.isNotBlank(location), o -> o.like(BuildHouseDO::getLocationZhCn, location)
                        .or().like(BuildHouseDO::getLocationEnUs, location))
                .orderByDesc(BuildHouseDO::getId));
    }

}